import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BaHttp } from '../../../theme/baHttp/baHttp.service';
import { SearchBusiness } from '../searchBusiness/searchBusiness';
import { Addbusiness } from '../addbusiness/addbusiness';
@Component({
  selector: 'business-page',
  templateUrl: 'business.html'
})
export class Business {
  items = [];
  tabBarElement: any;
  constructor(
    public navCtrl: NavController,
    private _http: BaHttp
  ) {
    if (document.querySelector('.tabbar')) {
      this.tabBarElement = document.querySelector('.tabbar.show-tabbar');
    }
    this._http.post('http://localhost:31173/business/send', "", (res) => {
      for (let i = 0; i < res.length; i++) {
        this.items.push(res[i]);
      }
    })
  }
  ionViewWillEnter() {
    if (this.tabBarElement) {
      this.tabBarElement.style.display = 'none';
    }
  }

  ionViewWillLeave() {
    if (this.tabBarElement) {
      this.tabBarElement.style.display = 'flex';
    }
  }
  doRefresh(refresher) {
    setTimeout(() => {
      this.items = [];
      this._http.post('http://localhost:31173/business/send', "", (res) => {
        for (let i = 0; i < res.length; i++) {
          this.items.push(res[i]);
        }
      })
      refresher.complete();
    }, 2000);
  }
  doInfinite(infiniteScroll) {
    setTimeout(() => {
      this._http.post('http://localhost:31173/business/send', "", (res) => {
        for (let i = 0; i < res.length; i++) {
          this.items.push(res[i]);
        }
      })
      infiniteScroll.complete();
    }, 1000);
  }
  public searchApp(): void {
    this.navCtrl.push(SearchBusiness);
  }
  public Addbusiness(): void {
    this.navCtrl.push(Addbusiness);
  }
  public removeItem(data:any):void{
    for (let i = 0; i < this.items.length; i++) {
           if(this.items[i]===data){
             this.items.splice(i, 1);
           }
        }
  }
}